<template>
  <div>
    <x-header
      :right-options="{showMore: true}"
      @on-click-more="showMenus"
    >设备列表</x-header>
    <group>
      <lightcell
        v-for="item in deviceListdata"
        v-if="item.type==='1'"
        v-bind:title="item.name"
        :itemdata="item"
      ></lightcell>
      <lightcell
        v-for="item in deviceListdata"
        v-if="item.type==='2'"
        v-bind:title="item.name"
        :itemdata="item"
      ></lightcell>
      <lightcell
        v-for="item in deviceListdata"
        v-if="item.type==='3'"
        v-bind:title="item.name"
        :itemdata="item"
      ></lightcell>
    </group>

    <!--<group>-->
    <!--<cell is-link title="title" value="value" v-for="item in deviceListdata" v-if="item.type==1" v-bind:title="item.name" :link = "{name:'lightDetail',params:item,query:{a:'queryXXXX'}}">-->
    <!--<div style="background-color: teal;width: 100px;height: 100px">-->
    <!--</div>-->
    <!--</cell>-->
    <!--<cell is-link title="title" value="value" v-for="item in deviceListdata" v-if="item.type==2" v-bind:title="item.name"></cell>-->
    <!--</group>-->
    <!-- {{count}} -->
  </div>
</template>

<script>
import Lightcell from "../../components/devicecell/lightcell";
import Plugcell from "../../components/devicecell/plugcell";
import store from "../../store/store";
export default {
  components: {
    Plugcell,
    Lightcell,
    store
  },
  name: "devList",

  beforeRouteLeave(to, from, next) {
    // 设置下一个路由的 meta
    if (to.path == "/lightDetail") {
      to.meta.keepAlive = false;
    }
    // B 跳转到 A 时，让 A 缓存，即不刷新
    next();
  },
  data() {
    return {
      deviceListdata: [],
      testData: store.state.mqttMessage
    };
  },
  mounted() {
    // // 显示
    // this.$vux.alert.show({
    //   title: 'Vux is Cool',
    //   content: 'Do you agree?',
    //   onShow () {
    //     console.log('Plugin: I\'m showing')
    //   },
    //   onHide () {
    //     console.log('Plugin: I\'m hiding')
    //   }
    // })
  },
  created() {
    console.info("提示信息");
    this.getGoodsList();
  },
  methods: {
    getGoodsList() {
      var that = this;
      console.log(store.state.mqttMessage);
      // store.commit('updateText','asdfasdf')
      this.$api.device.deviceList().then(res => {
        that.deviceListdata = res.data.data;
        console.info(that.deviceListdata);
      });
    },
    showMenus(params) {
      
      Cordova.exec(
        this.netWorkSetupSuccess,
        this.netWorkSetupFailed,
        "DeviceControl",
        "coolMethod",
        ["我是JS传的参数！"]
      );

       Cordova.exec(
        this.netWorkSetupSuccess,
        this.netWorkSetupFailed,
        "SmartHomeMqttPlug",
        "coolMethod",
        ["我是JS传的参数！"]
      );

    },
    netWorkSetupSuccess: function() {},
    netWorkSetupFailed: function() {}
  },
  computed: {
    count() {
      return store.state.mqttMessage;
      // Or return basket.getters.fruitsCount
      // (depends on your design decisions).
    }
  },
  watch: {
    count(newCount, oldCount) {
      // Our fancy notification (2).
      console.log(`We have ${newCount} fruits now, yaay!`);
    }
  }
};
</script>

<style scoped>
</style>
